﻿using System;
using System.IO;

namespace Anmlz.Services
{
    using Anmlz.Services.Contracts;

    public class FileNameService : IFileNameService
    {
        private readonly IConfigService _configService;

        public FileNameService(IConfigService configService)
        {
            _configService = configService;
        }

        public bool IsImageExtensionValid(string url)
        {
            try
            {
                var ext = Path.GetExtension(url);
                switch (ext)
                {
                    case ".jpg":
                    case ".jpeg":
                    case ".png":
                        return true;
                        default:
                        return false;
                }
            }
            catch
            {
                return false;
            }
        }

        public string GetUniqueFileName(string path)
        {
           return string.Format("{0}{1}", Guid.NewGuid(), Path.GetExtension(path));
        }

        public string GetPathForSavingImage(string imageName)
        {
           return string.Format("{0}\\{1}", _configService.ImagesFolderPath, imageName);
        }

        public string GetImageUrl(string imageName)
        {
            return string.Format("{0}//{1}", _configService.ImagesHttpUrl, imageName);
        }
    }
}
